from lib.ZNode import ZNode
from pygame import display as pdis
from lib.ZScreen import scenes


class FadeOut ( ZNode ) :
    def __init__ ( self , father , scene ) :
        super ( FadeOut , self ).__init__ ( father )
        self.image = pdis.get_surface ( ).copy ( )
        self.image.set_alpha ( 255 )
        self._running = True
        self.scene = scene
        self.scenes = scenes
        for x in self.scenes :
            self.scenes.remove ( x )
        self.scenes.append ( self )
        self.speed = 7

    def draw ( self ) :
        if self._running :
            if self.image.get_alpha ( ) > 0 :
                alpha = self.image.get_alpha ( ) - self.speed
                self.image.set_alpha ( alpha )
                self.father.screen.blit ( self.image , [ 0 , 0 ] )
            else :
                self._running = False
                from lib.ZDirection import ZDirection
                ZDirection ( )._change_scene ( self.scene )
